import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
//      如果不传入，则不能用上面的
        LinkedList<Integer> list = new LinkedList<>(arrayList);
        list.add(4);
        list.add(5);
        System.out.println(list);
        System.out.println("====");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        System.out.println("====");
//        迭代器遍历，从前往后
        ListIterator<Integer> it = list.listIterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
        System.out.println("====");
//        迭代器遍历，从后往前
        ListIterator<Integer> it2 = list.listIterator(list.size());
        while(it2.hasPrevious()){
            System.out.print(it2.previous()+" ");
        }
        System.out.println();
        System.out.println("====");
    }
    public static void main2(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.clear();

        MyLinkedList myLinkedList = new MyLinkedList();

        myLinkedList.addFist(1);
        myLinkedList.addFist(2);
        myLinkedList.addFist(3);
        myLinkedList.addFist(4);
        myLinkedList.addFist(5);
//        myLinkedList.display();
        myLinkedList.addLast(99);
//        myLinkedList.display();
//        myLinkedList.remove(2);
//        myLinkedList.remove(5);
//        myLinkedList.display();
        myLinkedList.Index(1,111);
        myLinkedList.addLast(2);
        myLinkedList.addLast(2);
        myLinkedList.addLast(2);
        myLinkedList.removeAllKey(2);
        myLinkedList.display();
    }
    public static void main1(String[] args) {
//        MySingleList mySingleList = new MySingleList();
//        mySingleList.createList();
//        System.out.println("===");
//        mySingleList.display();
//        System.out.println();
//        System.out.println("===");
//        System.out.println(mySingleList.size());
//        System.out.println("===");
//        mySingleList.removeAllKey(2);
//        System.out.println("===");
//        mySingleList.addFist(6);
//        mySingleList.addFist(7);
//        mySingleList.addFist(8);
//        mySingleList.display();
//        System.out.println("===");
//        mySingleList.addLast(88);
//        mySingleList.display();
//        mySingleList.Index(2,1);
//        System.out.println("===");
//        mySingleList.Index(0,1);
//        mySingleList.addLast(22);
//        mySingleList.addLast(33);
//        mySingleList.addLast(44);
//        mySingleList.addLast(55);
//        mySingleList.Index(3,333);
//        mySingleList.display();

        MySingleList mySingleList = new MySingleList();
        mySingleList.Index(0,1);
        mySingleList.Index(1,111);
        mySingleList.addLast(2);
        mySingleList.addLast(1);
        mySingleList.addLast(2);
        mySingleList.addLast(2);
        mySingleList.addLast(1);
        mySingleList.addLast(1);
//        mySingleList.removeAllKey(1);
        mySingleList.display();
        mySingleList.remove(111);
        mySingleList.display();
    }
}